package com.example.h2_module.controller;

import com.example.h2_module.entity.User;
import com.example.h2_module.mapper.UserMapper;
import com.example.h2_module.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description
 * @Author lihw
 * @Date 2024/5/30 10:36
 */
@RestController
@RequestMapping("test")
public class TestController {

    @Autowired
    private UserService userService;
    @Autowired
    private UserMapper userMapper;

    @GetMapping("save")
    public Integer save(){

        User user = new User();
        user.setId(1);
        user.setUsername("张三");
        user.setPwd("123456e");
        user.setSalary(10000); //10k
        boolean flag = userService.save(user);
        System.out.println(flag ? "插入成功" : "插入失败");

        return flag ? 1 : 0;
    }

    @GetMapping("query")
    public List<User> query(){
        List<User> users = userMapper.selectList(null);
        return users;
    }

}
